<?php
namespace app\admin\module;

use app\common\model\Goods;
use app\common\model\GoodsCate;
use think\Exception;

class GoodscateModule{

    public static function page($pageSize= 10){
        return GoodsCate::where([])->order('id','desc')->paginate(10);
    }

    public static function create($data){
        $data['createtime'] = time();
        GoodsCate::create($data);
    }

    public static function update($data){
        $data['updatetime'] = time();
        GoodsCate::update($data,['id'=>$data['id']]);
    }

    public static function del($id){
        $exists = Goods::where(['cate_id'=>$id])->find();
        if($exists){
            throw new Exception("该分类正在使用，不能删除");
        }
        GoodsCate::destroy($id);
    }
}